package com.caowj.composedemo.activity

import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider

class PreviewActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Greeting(msg = Message("caowj", "body1111111111"))
        }
    }
}

data class Message(val author: String, val body: String)

class ChatProvider : PreviewParameterProvider<Message> {
    private val aa = Message("aa", "bb")
    private val bb = Message("cc", "dd")
    override val values: Sequence<Message>
        get() = listOf(aa, bb).asSequence()
}

@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true, name = "Dark Mode")
@Composable
fun Greeting(
    @PreviewParameter(provider = ChatProvider::class) msg: Message
) {
    Text(text = "Hello ${msg.author}!")
}